package com.offcn.controller;


import com.offcn.pojo.Ordersetting;
import com.offcn.service.OrdersettingService;
import com.offcn.utils.MessageConstant;
import com.offcn.utils.POIUtils;
import com.offcn.utils.Result;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xinyi
 * @since 2021-07-14
 */
@RestController
@RequestMapping("/ordersetting")
public class OrdersettingController {

    @Reference
    private OrdersettingService ordersettingService;

    @RequestMapping("/getOrdersettingByDate")
    public Result getOrdersettingByDate(String date){
        return ordersettingService.getOrdersettingByDate(date);
    }

    @RequestMapping("/uploadTempleate")
    public Result uploadTempleatete(MultipartFile excelFile){
        try {
            List<String[]> stringList = POIUtils.readExcel(excelFile);
            ordersettingService.uploadTempleatete(stringList);
        } catch (IOException e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.IMPORT_ORDERSETTING_FAIL);
        }
        return new Result(true, MessageConstant.IMPORT_ORDERSETTING_SUCCESS);
    }

    @RequestMapping("/editNumberByDate")
    public Result editNumberByDate(@RequestBody Ordersetting ordersetting){
        return ordersettingService.editNumberByDate(ordersetting);
    }

}

